package net.obxlabs.tweetpad.behaviour;

import java.awt.*;
import net.nexttext.*;
import net.nexttext.behaviour.*;
import net.nexttext.behaviour.standard.*;
import net.nexttext.behaviour.control.*;
import net.nexttext.input.*;
import net.nexttext.processing.*;
import net.nexttext.property.BooleanProperty;

/**
 * 
 * $Id: OnDrop.java 22 2007-11-28 15:38:18Z prisonerjohn $
 */
public class OnDrop extends Condition {
	protected Mouse mouse;
    protected int buttonToCheck;
    protected Rectangle bounds;

    public OnDrop(Action trueAction, Rectangle bounds) {
        this(ProcessingMouse.BUTTON1, trueAction, bounds);
    }
    
    public OnDrop(int buttonToCheck, Action trueAction, Rectangle bounds) {
        super(trueAction, new DoNothing());
        this.buttonToCheck = buttonToCheck;
        this.bounds = bounds;
    }
    
    /**
     * Checks whether or not the mouse is released over the bounds.
     * 
     * @param to the TextObject to consider
     * 
     * @return the outcome of the condition
     */
    public boolean condition(TextObject to) {
    	BooleanProperty dragging = (BooleanProperty)to.getProperty("Dragging");
    	if (dragging != null) {
    		if (dragging.get()) {
    			// TextObject was being dragged at the last frame, check drop location
    			if (bounds.intersects(to.getBounds())) {
    				return true;
    			}
    		}
    	}
    	
    	return false;
    }
}
